package zouran.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import zouran.entity.User;
import zouran.service.UserService;
/**
 * @Author: zouran
 * @Description:
 * @Date: Created in 2022 2022/12/4 13:03
 **/
@RestController
@CrossOrigin
@RequestMapping(value = "/user")
public class UserController {
    private UserService userService;
    @Autowired
    public void setUserService(UserService userService) {
        this.userService = userService;
    }

    /**
     * 注册入口
     * @param user 用户类
     * @return 0代表已注册,1代表注册成功
     */
    @RequestMapping("/signIn") //注册入口
    public int signIn(@RequestBody User user){
       return userService.sign(user);
    }

    /**
     * 判断账号是否注册及密码是否正确,0对应未注册,1代表密码错误，2代表正确
     * @param phone 手机号码
     * @param password 密码
     * @return 0,1,2
     */
    @RequestMapping("/judge_loginIn")
    public int judge_user(@RequestParam("phone") String phone,@RequestParam("password") String password){
        return userService.judge_user(phone, password);
    }

    /**
     * 传入的是对象，进行更改信息，密码错误返回0，成功返回1
     * @param user 对象信息
     * @return 0或1
     */
    @RequestMapping("/update_myself")
    public int update_myself (@RequestBody User user)
    {
        return userService.update_myself(user);
    }

    /**
     * 注销账号
     * @param user 对象
     * @return true/false
     */
    @RequestMapping("/logout_myself")
    public boolean logout_myself(@RequestBody User user){
        return userService.logout_myself(user);
    }
}
